#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > r12_cabs.info <<'%EOF%'
   r12_cabs
   -----------
   Molecule:         Methane (CH4)
   Wave Function:    MP2-R12 / Turbomole-TZV
   Test Purpose:     Check R12 method with complementary auxiliary basis
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > r12_cabs.mol <<'%EOF%'
INTGRL
Methane                                                                         
                                                                                
    4  0 0            0.10D-14
 1      6.    1    2    1    1
C        1.0900000000000    -0.1200000000000     7.2890100000000
H  11    5
    13575.3496800000        0.0002224600        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
     2035.2333680000        0.0017232700        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
      463.2256236000        0.0089255700        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
      131.2001960000        0.0357279800        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
       42.8530158900        0.1107626000        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
       15.5841857700        0.2429562800        0.0000000000        0.0000000000
                            0.0000000000        0.0000000000
        6.2067138500        0.0000000000        0.4144026300        0.0000000000
                            0.0000000000        0.0000000000
        2.5764896500        0.0000000000        0.2374496900        0.0000000000
                            0.0000000000        0.0000000000
        0.5769633900        0.0000000000        0.0000000000        1.0000000000
                            0.0000000000        0.0000000000
        0.2297283100        0.0000000000        0.0000000000        0.0000000000
                            1.0000000000        0.0000000000
        0.0951644400        0.0000000000        0.0000000000        0.0000000000
                            0.0000000000        1.0000000000
H   6    3
       34.6972322400        0.0053333700        0.0000000000        0.0000000000
        7.9582622800        0.0358641100        0.0000000000        0.0000000000
        2.3780826900        0.1421587300        0.0000000000        0.0000000000
        0.8143320800        0.3427047200        0.0000000000        0.0000000000
        0.2888754700        0.0000000000        1.0000000000        0.0000000000
        0.1005682400        0.0000000000        0.0000000000        1.0000000000
 1      1.    4    1    1
H        2.8715308320486     0.1736528344531     8.5657410000000
H       -0.6915308320486    -0.4136528344531     8.5657410000000
H        0.7963471655469     1.6615308320486     6.0122790000000
H        1.3836528344531    -1.9015308320486     6.0122790000000
H   5    3
       34.0613410000        0.0060252000        0.0000000000        0.0000000000
        5.1235746000        0.0450210900        0.0000000000        0.0000000000
        1.1646626000        0.2018972600        0.0000000000        0.0000000000
        0.3272304000        0.0000000000        1.0000000000        0.0000000000
        0.1030724000        0.0000000000        0.0000000000        1.0000000000
 2      0.    1    3    0    0    1
C        1.0900000000000    -0.1200000000000     7.2890100000000
H   1    1
        0.8000000000        1.0000000000
 2      0.    4    2    0    1
H        2.8715308320486     0.1736528344531     8.5657410000000
H       -0.6915308320486    -0.4136528344531     8.5657410000000
H        0.7963471655469     1.6615308320486     6.0122790000000
H        1.3836528344531    -1.9015308320486     6.0122790000000
H   1    1
        0.8000000000        1.0000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > r12_cabs.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
.DIRECT
*MOLBAS
.R12AUX
**INTEGRALS
.R12RSG
0.5
3
**WAVE FUNCTIONS
.CC
*ORBITALS
.MOSTART
 H1DIAG
.FROZEN
 1
.R12ORB
 7
*SCF INPUT
.THRESHOLD
 1D-10
*CC INPUT
.HERDIR
.MP2
.PRINT
 3
*R12
.CABS
.R12XXL
**END OF DALTON INPUT
%EOF%

#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >r12_cabs.check
cat >>r12_cabs.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#
#             MP2-R12/B   correlation energy =   -0.179894117
#             MP2-R12/B   correlation energy =   -0.163731939
#             MP2-R12/B   correlation energy =   -0.172522152
#             MP2-R12/B   correlation energy =   -0.172522152
#
CRIT1=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.17989411" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=1
ERROR[1]="Conventional MP2-R12/B ENERGY NOT CORRECT"

CRIT2=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.16373193" $log | wc -l`
TEST[2]=`expr	$CRIT2`
CTRL[2]=1
ERROR[2]="Ansatz 1 MP2-R12/B ENERGY NOT CORRECT"

CRIT3=`$GREP "MP2-R12/B   correlation energy =   (-0| -)\.17252215" $log | wc -l`
TEST[3]=`expr	$CRIT3`
CTRL[3]=2

ERROR[1]="Ansatz 2/3 MP2-R12/B ENERGY NOT CORRECT"

PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
